﻿namespace DafYomiLib
{
    using System;
    using System.Globalization;

    public static class DateTimeExtensions
    {
        private const string HebrewCultureName = "he-IL";
        private static readonly CultureInfo HebrewCulture =
#if SILVERLIGHT
            new CultureInfo(HebrewCultureName);
#else
CultureInfo.CreateSpecificCulture(HebrewCultureName);
#endif
        /// <summary>
        /// Converts a Gregorian date to its Hebrew date string representation,
        /// using custom DateTime format string.
        /// </summary>
        /// <param name="value">The <see cref="DateTime"/> value to convert.</param>
        /// <param name="format">A standard or custom date and time format string.</param>
        public static string ToJewishDateString(this DateTime value, string format)
        {
            HebrewCulture.DateTimeFormat.Calendar = new HebrewCalendar();
            return value.ToString(format, HebrewCulture);
        }

        /// <summary>
        /// Converts a Gregorian date to its Hebrew date string representation,
        /// using DateTime format options.
        /// </summary>
        /// <param name="value">The <see cref="DateTime"/> value to convert.</param>
        /// <param name="dayOfWeek">Specifies whether the return string should
        /// include the day of week.</param>
        public static string ToJewishDateString(this DateTime value, bool dayOfWeek)
        {
            var format = dayOfWeek ? "D" : "d";
            return value.ToJewishDateString(format);
        }
    }
}